//
//  SpringGraph_TestViewController.m
//  SpringGraph Test
//
//  Created by Jack Herrington on 5/30/10.
//  Copyright Myself 2010. All rights reserved.
//

#import "SpringGraph_TestViewController.h"
#import "SGExampleNode.h"

@implementation SpringGraph_TestViewController

- (IBAction)sliderChanged:(id)sender {
	springGraph.repulsionFactor = repulsionSlider.value;
}

- (void)itemTouched:(id)sender view:(UIView *)view {
	springGraph.distinguishedView = view;
}

static int s_nAddSeq = 1;

- (IBAction)newNode:(id)sender {
	SGExampleNode *foo = [[[SGExampleNode alloc] initWithText:[NSString stringWithFormat:@"%d",s_nAddSeq++]] autorelease];
	[springGraph addSubview:foo];
	[springGraph connect:foo to:springGraph.distinguishedView];
}

- (IBAction)deleteNode:(id)sender {
	if ( springGraph.distinguishedView ) {
		[springGraph.distinguishedView removeFromSuperview];
	}
}

- (void)viewDidLoad {
	[super viewDidLoad];

	springGraph = [[SGSpringGraph alloc] initWithFrame:springGraphHost.frame];
	[springGraphHost addSubview:springGraph];
	
	SGExampleNode *foo = [[[SGExampleNode alloc] initWithText:@"Foo"] autorelease];
	[springGraph addSubview:foo];
	SGExampleNode *bar = [[[SGExampleNode alloc] initWithText:@"Bar"] autorelease];
	[springGraph addSubview:bar];
	SGExampleNode *baz = [[[SGExampleNode alloc] initWithText:@"Baz"] autorelease];
	[springGraph addSubview:baz];

	SGEdgeData *ed = [springGraph connect:foo to:bar];
	ed.lineWidth = [NSNumber numberWithInt:20];
	[springGraph connect:bar to:baz];
 
	springGraph.delegate = self;
	springGraph.distinguishedView = foo;
}

// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return YES;
}

- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}


- (void)dealloc {
	[springGraph release];
    [super dealloc];
}

@end
